<template>
  <div class="reply-container">
    <div class="tit">
      <span>{{item.reply_count}}</span>条回复
    </div>
    <div class="pinlun">
      <recomment-item :item="item"></recomment-item>
    </div>
    <div class="reply">全部回复</div>
    <div class="replyList">
      <div v-for="(item2, index) in replyList" :key="index">
        <recomment-item :item="item2"></recomment-item>
      </div>
    </div>
    <div class="reply">已显示全部评论</div>
    <div class="writecomment">
      <van-cell-group>
        <van-cell>
          <van-button id="replys" type="default" round size="large" @click="showProp">写评论</van-button>
        </van-cell>
      </van-cell-group>
    </div>
    <!-- 弹出层 -->
    <recomments :show="show" :target="item.com_id" :artId="artId" @repl="getreplys"></recomments>
    <!-- 弹出层 -->
  </div>
</template>
<script>
import recommentItem from "./recomment-item";
import recomments from "./recomments";
import { getRecomments_api, addRecomments_api } from "@/api/user.js";
export default {
  props: {
    item: {
      type: [Array, Object, String],
    },
    artId: {
      type: [Number, String],
      required: true,
    },
  },
  data() {
    return {
      replyList: [],
      show: false,
    };
  },
  created() {
    this.getRecomments();
  },
  methods: {
    // 获取评论回复
    async getRecomments() {
      // 获取评论id
      var id = this.item.com_id.toString();
      const { data: res } = await getRecomments_api({ type: "c", source: id });
      //   console.log(res);
      this.replyList = res.data.results;
    },
    // 点击回复显示弹出层
    showProp() {
      this.show = true;
    },
    // 接收发布评论回复数据
    getreplys(val) {
      this.show = false;
      this.replyList.unshift(val);
      this.item.reply_count++;
      console.log(this.replyList, "评论回复");
    },
  },
  components: {
    recommentItem,
    recomments,
  },
};
</script>
<style lang='less' scoped>
.reply-container {
  position: relative;
  width: 100%;
  padding: 0 30px;
  /deep/ .tit {
    height: 110px;
    font-size: 28px !important;
    padding-left: 300px !important;
    line-height: 110px;
  }
  .pinlun {
    .active {
      color: #e5645f;
    }
    .authorinfo {
      height: 120px;
      display: flex;
      justify-content: space-between;
      padding: 20px 0;
      .left {
        display: flex;
        img {
          vertical-align: middle;
          margin-right: 20px;
        }
        .name {
          color: #6bb4eb;
        }
        .info {
          font-size: 24px;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
        }
      }
      .van-button {
        margin-left: 20px;
        width: 150px;
        height: 50px;
        .van-button__text {
          font-size: 12px;
          color: #000;
        }
      }
    }
  }
  .reply {
    height: 110px;
    line-height: 110px;
    font-size: 28px;
    text-align: center;
  }
  .writecomment {
    position: absolute;
    bottom: 0;
    width: 100%;
    .van-button--round {
      width: 500px;
      height: 70px;
      margin-left: 50px;
    }
  }
}
</style>